local skel = fk.CreateSkill{
  name = "re__heyi",
  tags = { Skill.Compulsory }
}
local H = require "packages/hegemony/util"
local heyi = H.CreateArraySummonSkill{
  name = "re__heyi",
  array_type = "formation",
}
---@type TrigSkelSpec<DeathTrigFunc>
local heyiTrig = {
  visible = false,
  can_refresh = function(self, event, target, player, data)
    if event == fk.EventLoseSkill then return data == heyi
    elseif event == fk.GeneralHidden then return player == target
    else return player:hasShownSkill(skel.name, true, true) end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local ret = #room.alive_players > 3 and player:hasSkill(self)
    for _, p in ipairs(room.alive_players) do
      if (H.inFormationRelation(p, player) and p ~= player ) or p == player then
        room:handleAddLoseSkills(p, ret and 'feiying' or "-feiying", nil, false, true)
      end
    end
  end,
}
--skel:addEffect("arraysummon", heyi)
skel:addEffect(fk.TurnStart, heyiTrig)
skel:addEffect(fk.GeneralRevealed, heyiTrig)
skel:addEffect(fk.EventAcquireSkill, heyiTrig)
skel:addEffect(fk.RemoveStateChanged, heyiTrig)
skel:addEffect(fk.EventLoseSkill, heyiTrig)
skel:addEffect(fk.GeneralHidden, heyiTrig)
skel:addEffect(fk.Deathed, heyiTrig)
return skel